package com.tsyz.servlet.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

@Service
public class ComplianceServiceImpl {

    // 注入提交合规任务的线程池
    @Autowired
    @Qualifier("submitComplianceTaskPool") // 指定线程池Bean名称（避免歧义）
    private ThreadPoolTaskExecutor submitPool;

    // 异步提交合规任务
    public CompletableFuture<String> submitTask(String taskId) {
        // 使用自定义线程池执行异步任务
        return CompletableFuture.supplyAsync(() -> {
            // 模拟任务执行：如调用外部接口、处理数据
            try {
                Thread.sleep(1000); // 模拟耗时
                System.out.println("任务" + taskId + "提交完成，线程：" + Thread.currentThread().getName());
                return "任务" + taskId + "处理成功";
            } catch (InterruptedException e) {
                throw new RuntimeException("任务执行中断", e);
            }
        }, submitPool); // 传入自定义线程池
    }
}